home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows1 / commdem2.zip / READ.TXT < prev    next >
Text File  |  1992-02-04  |  7KB  |  132 lines

  1. Visual Basic Communications Demonstration Program: COMMDEMO
  2.  
  3. The Visual Basic COMMDEMO program was designed to demonstrate how to call 
  4. the communications related Windows API functions to establish basic serial 
  5. communications.  The COMMDEMO sample program is an example of a simple 
  6. terminal emulation program.  This program was designed mainly for 
  7. educational purposes and therefore is not an example of a full featured 
  8. terminal emulation program.  The concepts presented in this sample program 
  9. should provide a solid foundation from which you can implement serial 
  10. communications into your own Visual Basic application.
  11.  
  12. The sample program contains comments where needed indicating other possible 
  13. values for variable settings to allow you to easily modify the sample 
  14. program.  For example you could modify the sample program to open any 
  15. communications port; or change the line and event settings to your own 
  16. custom settings.
  17.  
  18. The COMMDEMO sample program demonstrates the following:
  19.  
  20.      o How to open and connect to the communications port
  21.      o How to read from the communications port
  22.      o How to write to the communications port
  23.      o How to change the port settings such as the baud rate
  24.      o How to change the event settings such as detecting when a character 
  25.        is received.
  26.      o How to trap and process errors after calling the communications 
  27.        related API functions.
  28.  
  29. Cross-Reference of the Main Features
  30. ---------------------------------------------------------------------------
  31. The following list provides references to the main functional areas of the 
  32. program.  The following reference should make it easier for you to find a 
  33. desired feature related to communications.  All of the procedures listed 
  34. below are contained in the main form called COMMDEMO.FRM.
  35.  
  36. o How to open and connect to the communications port:
  37.  
  38.    The code to initialize the communications port line settings is located 
  39.    in the Form_Load event procedure.  The communications port line settings 
  40.    are initialized by calling the Windows API function BuildCommDCB.
  41.  
  42.    The code to open the communications port is located in function 
  43.    CommConnect.  Function CommConnect calls the functions SetLineSettings 
  44.    and SetEventSettings which demonstrate how to set the communications 
  45.    line (e.g., baud rate, stop bits, hardware handshaking) and event (e.g., 
  46.    ring detect) settings respectively.  The function CommConnect calls the 
  47.    Windows API function OpenComm to open COM1.  The function CommConnect 
  48.    contains a call to the Windows API function SetCommState to set the 
  49.    communications line settings.  The function SetEventSettings contains a 
  50.    call to the windows API function SetCommEventMask to enable 
  51.    communications event trapping.
  52.  
  53.    Function CommConnect is called from the MNU_Connect_Click event 
  54.    procedure for the Connect! menu.
  55.  
  56. o How to read from the communications port
  57.  
  58.    The code that reads in all characters waiting in the communications 
  59.    receive buffer is located in the Timer_CheckInBuf_Timer event procedure.  
  60.    If a successful connection is made, the timer is initiated from the 
  61.    CommConnect function .  The timer is disabled in the CommDisconnect 
  62.    function.  The Timer_CheckInBuf_Timer event procedure contains a call to 
  63.    the Windows API function ReadComm to read the characters waiting in the 
  64.    receive buffer. 
  65.  
  66. o How to write to the communications port
  67.  
  68.    The Text_TransmitWin_KeyPress event procedure contains the code which 
  69.    writes characters to the communications port as they are entered in the 
  70.    transmit window.  This event procedure contains a call to the Windows 
  71.    API function WriteComm to write characters to the transmit buffer.
  72.  
  73. o How to change the port settings such as the baud rate.
  74.  
  75.    The MNU_BaudRate_Click event procedure for the Baud menu demonstrates 
  76.    how to change the baud rate.  The baud rate can be changed while the 
  77.    communications port is opened or closed.  COMMDEMO demonstrates how to 
  78.    change between baud rates of 1200, 4800 and 9600.  The 
  79.    MNU_BaudRate_Click event procedure demonstrates how to call the Windows 
  80.    API function SetCommState to change the baud rate line setting.
  81.  
  82. o How to change the event settings such as detecting when a character is 
  83.   received.
  84.  
  85.    The MNU_Events_CharDetect_Click event procedure for the Events menu 
  86.    demonstrates how to enable or disable character received events.  When 
  87.    character detect event trapping is enabled, a message is displayed in 
  88.    the Communications Status window each time a character is received.  The 
  89.    character detect event trapping can only be enabled or disabled when the 
  90.    communications port is opened.  The MNU_Events_CharDetect_Click event 
  91.    procedure contains a call to the Windows API function SetCommEventMask 
  92.    to change the character detect event setting.
  93.  
  94. o How to trap and process errors after calling the communications related 
  95.   API functions.
  96.  
  97.    The function GetOpenCommError demonstrates how to process errors related 
  98.    to opening the communications port.  This function simply interprets the 
  99.    return code from the Windows API function OpenComm.  The 
  100.    GetOpenCommError function is called from the CommConnect function.
  101.  
  102.    The function ProcessCommError demonstrates how to call the Windows API 
  103.    function GetCommError to process general communications errors.  This 
  104.    function is called from the procedures Timer_CheckInBuf_Timer and 
  105.    Text_TransmitWin_KeyPress when reading from and writing to the 
  106.    communications port respectively.
  107.  
  108. Cross-Reference to the Windows API functions called by COMMDEMO
  109. ---------------------------------------------------------------------------
  110. Below is a reference to the location(s) in the code where the 
  111. communications related Windows API functions are called.  All calls to the 
  112. Windows API functions are located in the main form called COMMDEMO.FRM.  
  113. The declaration for the Windows API functions and related Type ... End Type 
  114. structures is located in the global module called COMMDEMO.GLB.
  115.  
  116.     Windows API function       Location in COMMDEMO.FRM
  117.     --------------------       --------------------------------------------
  118.     BuildCommDCB...............Form_Load event procedure
  119.     OpenComm...................CommConnect
  120.     CloseComm..................CommConnect
  121.              ..................CommDisconnect
  122.     FlushComm..................CommDisconnect
  123.     ReadComm...................Timer_CheckInBuf_Timer event procedure
  124.     WriteComm..................Text_TransmitWin_KeyPress event procedure
  125.     SetCommState...............SetLineSettings
  126.                 ...............MNU_BaudRate_Click event procedure
  127.     SetCommEventMask...........SetEventSettings
  128.                     ...........MNU_Events_CharDetect_Click event procedure
  129.     GetCommError...............ProcessCommError
  130.                 ...............Timer_CheckInBuf_Timer event procedure
  131.  
  132.